 /*
  * Copyright (c) 2021, 2023, yishun.cn All rights reserved.
  *
  */
 package cn.shun.controller;

 import cn.hutool.core.util.ObjUtil;
 import cn.shun.dao.ProductDao;
 import cn.shun.local.LocalUserThreadLocal;
 import cn.shun.model.LocalUser;
 import cn.shun.model.Product;
 import cn.shun.model.ProductQuery;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;

 import java.util.List;

 /**
  * <p>Project: sboot_2023-cn.shun.controller-UploadController
  * <p>Powered by yishun On 2023-04-17 18:15:24
  *
  * @author yishun [2465734101@qq.com]
  * @version 1.0
  * @since 17
  */
 @RestController
 @Slf4j
 @RequestMapping("/api/product")
 public class ProductController {

     @Resource
     private ProductDao productDao;

     @GetMapping
     public List<Product> select(ProductQuery query) {
         //如果前端你不传status，那么我默认查询状态是1的列表
         if (ObjUtil.isEmpty(query.getStatus())) {
             query.setStatus(1);
         }
         return productDao.select(query);
     }

     @PostMapping
     public Integer insert(@RequestBody Product product) {
         LocalUser localUser = LocalUserThreadLocal.get();
         product.setLastUpdateBy(localUser.getTel());
         return productDao.insert(product);
     }

     @PutMapping
     public Integer update(@RequestBody Product product) {
         LocalUser localUser = LocalUserThreadLocal.get();
         product.setLastUpdateBy(localUser.getTel());
         return productDao.update(product);
     }

     @DeleteMapping
     public Integer delete(@RequestParam Integer id) {
         return productDao.delete(id);
     }

 }
